package com.axdoc.walletbiz.record.mq.service.impl;

import java.math.BigDecimal;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.axdoc.walletbiz.record.mq.message.Message;
import com.axdoc.walletbiz.record.mq.message.RiskMessage;
import com.axdoc.walletbiz.record.mq.service.MsgService;
import com.axdoc.walletbiz.record.service.RecordService;
/**
 * 支付成功-消息处理
 *
 */
@Component("riskService")
public class RiskServiceImpl implements MsgService {
	public static Logger logger = LoggerFactory.getLogger("listen_message");
	
	@Autowired
	private RecordService recordService;
	@Override
	public void handle(Message msg) {
		try {
			RiskMessage message=(RiskMessage) msg;
			logger.info("[处理风控消息,req,msg:"+message+" ]");
			String doc_id=message.getData().get("doc_id").toString();
			String biz_no=message.getData().get("biz_no").toString();
			BigDecimal balance=new BigDecimal(message.getData().get("balance").toString());
			Long biz_time = StringUtils.isEmpty(message.getData().get("biz_time").toString())
					? System.currentTimeMillis() : Long.valueOf(message.getData().get("biz_time").toString());
			String biz_type = message.getData().get("biz_type").toString();
			String income_id = message.getData().get("income_id").toString();
			String trade_no = message.getData().get("trade_num").toString();
			//开始记账
			recordService.risk(biz_no, doc_id, balance.intValue(), biz_time, biz_type, income_id, trade_no, msg.getId());
		} catch (Exception e) {
			logger.error("[处理风控消息异常,error,msg:"+msg,e);
		}
	}
	
}
